
import 'package:flutter_ahj_app/app/pctask/PcrwApiRequest.dart';
import 'package:flutter_ahj_app/app/yhpc/YhpcApiRequest.dart';
import 'package:flutter_ahj_app/base/basewidget/model/BaseModel.dart';
import 'package:rxdart/rxdart.dart';

class PcrwModel extends BaseModel {
  /// 获取培训任务列表
  BehaviorSubject<Map> _getPcrwList;
  Stream<Map> get getPcrwListStream => _getPcrwList.stream;

  getPcrwList(Map map) {
    _getPcrwList = BehaviorSubject();
    PcrwApiRequest.getPcrwApi(map).listen((event) {
      _getPcrwList.add(event);
      print(event);
    }, onError: (e) {
      _getPcrwList.add(null);
      errorData.add(e);
    });
  }

  /// 获取培训任务列表
  BehaviorSubject<Map> _getPcrwList1;
  Stream<Map> get getPcrwListStream1 => _getPcrwList1.stream;

  getPcrwList1(Map map) {
    _getPcrwList1 = BehaviorSubject();
    PcrwApiRequest.getPcrwfqApi(map).listen((event) {
      _getPcrwList1.add(event);
      print(event);
    }, onError: (e) {
      errorData.add(e);
    });
  }


  /// 风险点信息列表
  BehaviorSubject<Map> _fxdxxbservable;
  Stream<Map> get getFxdxxDataStream => _fxdxxbservable.stream;
  getfxdxxList(Map map) {
    _fxdxxbservable =  BehaviorSubject();
    PcrwApiRequest.fxdxxApi(map).listen((result){
      _fxdxxbservable.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  // 排查详情
  BehaviorSubject<Map> _pcdetailObservable;
  Stream<Map> get getpcDetailDataStream => _pcdetailObservable.stream;
  getpcDetail(var map) {
    _pcdetailObservable =  BehaviorSubject();
    PcrwApiRequest.pcDetailsApi(map).listen((result){
      _pcdetailObservable.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  //排查对象
  BehaviorSubject<Map> _pcupdateObservable;
  Stream<Map> get getHazardUpdateStream => _pcupdateObservable.stream;
  getHazardUpdate(var map) {
    _pcupdateObservable =  BehaviorSubject();
    PcrwApiRequest.pcupdateDataApi(map).listen((result){
      _pcupdateObservable.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  //排查撤回
  BehaviorSubject<Map> _pcupdateObservable1;
  Stream<Map> get getHazardUpdateStream1 => _pcupdateObservable1.stream;
  getHazardUpdate1(var map) {
    _pcupdateObservable1 =  BehaviorSubject();
    PcrwApiRequest.pcupdateBackDataApi(map).listen((result){
      _pcupdateObservable1.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  //排查隐患详情
  BehaviorSubject<Map> _getpcyhDetailsObservable;
  Stream<Map> get getpcyhDetailsStream => _getpcyhDetailsObservable.stream;
  getpcyhDetails(var map) {
    _getpcyhDetailsObservable =  BehaviorSubject();
    PcrwApiRequest.pcyhDetailsApi(map).listen((result){
      _getpcyhDetailsObservable.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  //隐患登记
  BehaviorSubject<Map> _pcrwyhdjObservable;
  Stream<Map> get yhdjDataStream => _pcrwyhdjObservable.stream;
  yhdj(var map) {
    _pcrwyhdjObservable =  BehaviorSubject();
    PcrwApiRequest.yhdjDataApi(map).listen((result){
      _pcrwyhdjObservable.add(result);
    },onError: (e){
      errorData.add(e);
    });
  }

  @override
  void dispose() {
    super.dispose();
    if (_getPcrwList != null) _getPcrwList.close();
    if (_getPcrwList1 != null) _getPcrwList1.close();
    if (_fxdxxbservable != null) _fxdxxbservable.close();
    if (_pcdetailObservable != null) _pcdetailObservable.close();
    if (_pcupdateObservable != null) _pcupdateObservable.close();
    if (_pcupdateObservable1 != null) _pcupdateObservable1.close();
    if (_getpcyhDetailsObservable != null) _getpcyhDetailsObservable.close();
    if (_pcrwyhdjObservable != null) _pcrwyhdjObservable.close();

  }
}
